import { apiClient } from './base'

// 房源信息管理API
export const houseApi = {
  // 分页查询房源信息
  async getHouseList(params) {
    const response = await apiClient.get('/fwxx', { params })
    return response
  },

  // 根据门牌地址查询
  async getHouseByAddress(mpdz) {
    const response = await apiClient.get('/fwxx/mpdz', { params: { mpdz } })
    return response
  },

  // 根据房屋功能查询
  async getHouseByFunction(fwgn) {
    const response = await apiClient.get('/fwxx/fwgn', { params: { fwgn } })
    return response
  },

  // 根据状态查询
  async getHouseByStatus(zt) {
    const response = await apiClient.get('/fwxx/zt', { params: { zt } })
    return response
  },

  // 根据经营方查询
  async getHouseByOperator(jyf) {
    const response = await apiClient.get('/fwxx/jyf', { params: { jyf } })
    return response
  },

  // 根据ID查询房源信息
  async getHouseById(id) {
    const response = await apiClient.get(`/fwxx/${id}`)
    return response
  },

  // 创建房源信息
  async createHouse(data) {
    const response = await apiClient.post('/fwxx', data)
    return response
  },

  // 更新房源信息
  async updateHouse(id, data) {
    const response = await apiClient.put(`/fwxx/${id}`, data)
    return response
  },

  // 删除房源信息
  async deleteHouse(id) {
    const response = await apiClient.delete(`/fwxx/${id}`)
    return response
  },

  // 更新房源状态
  async updateHouseStatus(id, status) {
    const response = await apiClient.put(`/fwxx/${id}/status`, null, { params: { status } })
    return response
  },

  // Excel导入
  async importExcel(file) {
    const formData = new FormData()
    formData.append('file', file)
    const response = await apiClient.post('/fwxx/import', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
    return response
  },

  // Excel导出
  async exportExcel(params) {
    const response = await apiClient.get('/fwxx/export', {
      params,
      responseType: 'blob'
    })
    return response
  },

  // 导出Excel模板
  async exportTemplate() {
    const response = await apiClient.get('/fwxx/export/template', {
      responseType: 'blob'
    })
    return response
  }
}

// 默认导出对象，与其他API保持一致
export default {
  getList: houseApi.getHouseList,
  create: houseApi.createHouse,
  getById: houseApi.getHouseById,
  update: houseApi.updateHouse,
  delete: houseApi.deleteHouse,
  updateStatus: houseApi.updateHouseStatus,
  importExcel: houseApi.importExcel,
  exportExcel: houseApi.exportExcel,
  exportTemplate: houseApi.exportTemplate,
  getByAddress: houseApi.getHouseByAddress,
  getByFunction: houseApi.getHouseByFunction,
  getByStatus: houseApi.getHouseByStatus,
  getByOperator: houseApi.getHouseByOperator
} 